<template>
  <div class="page-container">
    <!-- 开通-->
    <div class="box-wrapper active" v-if="thirdServiceDetail.jianlianEnabled">
      <div class="logo-title-wrapper">
        <span class="title">聚合支付服务</span>
        <div class="open">已开通</div>
      </div>
      <div class="text">如需关闭聚合支付服务请联系启程的工作人员 </div>
      <div class="btn-wrapper">
        <a-button
          type="outline"
          @click="goTo('/value-added/thirdPayment/aggregation/record', 'record')"
          v-if="usePermission('svms:value-added:third-payments:polymerisation:record')"
          >申请记录</a-button
        >
      </div>
      <div class="bill-wrapper flex-row" v-if="thirdServiceDetail.payedCount > 0">
        <span @click="goToBill" style="cursor: pointer">查看更多账单</span>
        <icon-right />
      </div>
      <div class="msg-wrapper flex-row">
        <div class="collection flex-col">
          <span>收款笔数</span>
          <span class="num">{{ thirdServiceDetail.payedCount || 0 }} 笔</span>
        </div>
        <div class="collection flex-col active">
          <span>收款总额：</span>
          <span class="num">{{ thirdServiceDetail.payedTotalAmount || 0 }} 元</span>
        </div>
      </div>
    </div>
    <!-- 未开通-->
    <div class="box-wrapper active" v-else>
      <div class="logo-title-wrapper">
        <span class="title">聚合支付服务</span>
        <div class="close">暂未开通</div>
      </div>
      <div class="text">如需开通聚合支付服务请联系启程的工作人员 </div>
      <div class="btn-wrapper">
        <a-button
          v-if="usePermission('svms:value-added:third-payments:polymerisation:apply')"
          type="primary"
          style="margin-right: 12px"
          @click="goTo('/value-added/thirdPayment/aggregation/apply/0', 'apply')"
          >申请开通</a-button
        >
        <a-button
          v-if="usePermission('svms:value-added:third-payments:polymerisation:record')"
          type="outline"
          @click="goTo('/value-added/thirdPayment/aggregation/record', 'record')"
          >申请记录</a-button
        >
      </div>
      <div class="bill-wrapper flex-row" style="margin-top: 24px" v-if="thirdServiceDetail.payedCount > 0">
        <span @click="goToBill" style="cursor: pointer">查看更多账单</span>
        <icon-right />
      </div>

      <div class="money-wrapper">
        <div class="money">
          <img src="@/assets/thirdPayment-aggregation-bg-1.png" alt="" />
          <div class="msg">
            <div class="money-title">支持多渠道支付</div>
            <div class="money-text">支持消费者使用支付宝、微信、云闪付扫码付款</div>
          </div>
        </div>
      </div>
      <div class="money-wrapper">
        <div class="money">
          <img src="@/assets/thirdPayment-aggregation-bg-2.png" alt="" />
          <div class="msg">
            <div class="money-title">实时获取支付结果</div>
            <div class="money-text">消费者扫码完成支付后，费用的状态根据消费者的支付结果实时返回</div>
          </div>
        </div>
      </div>
      <div class="money-wrapper">
        <div class="money">
          <img src="@/assets/thirdPayment-aggregation-bg-3.png" alt="" />
          <div class="msg">
            <div class="money-title">订单下的费用与账户流水关联绑定</div>
            <div class="money-text">订单中的费用，提供生成聚合收款码。运用真实准确的支付结果，确保账户的结算流水的准确性</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup name="Aggregation">
  import { reactive, onMounted } from 'vue'
  import { useRouter } from 'vue-router'
  import { usePermission } from '@/hooks/usePermission'
  import { thirdServiceStatistics } from '@/api/finance/thirdPayment'

  const router = useRouter()

  // 三方支付详情
  const initThirdService = {
    payedCount: '', // 支付笔数
    payedTotalAmount: '', // 支付总金额
    jianlianEnabled: '', // 服务状态
    jianlianEnabledName: '', // 服务状态名称
  }
  // 服务状态
  const thirdServiceDetail = reactive(initThirdService)
  const getDetailApi = () => {
    thirdServiceStatistics().then(({ result }) => {
      Object.assign(thirdServiceDetail, result)
    })
  }

  const goTo = (url) => {
    router.push({ path: url })
  }

  const goToBill = () => {
    // 跳转三方支付账单
    usePermission('svms:finance:tripartitePayment')
      ? router.push({ path: '/finance/tripartitePayment' })
      : Message.warning(`无法跳转，暂无三方支付账单的页面权限 `)
  }

  onMounted(() => {
    getDetailApi()
  })
</script>

<style lang="less" scoped>
  .page-container {
    padding-bottom: 0;
    .flex-row {
      display: flex;
      flex-direction: row;
      align-items: center;
    }
    .flex-col {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
    }

    .box-wrapper {
      display: flex;
      justify-content: flex-start;
      flex-direction: column;
      align-items: flex-start;
      width: 100%;
      height: 1;
      &.active {
        height: 78vh;
        padding: 10vh 0 0 7vh;
        background-image: url('@/assets/box-bg.png') !important;
        background-size: 100% 100%;
      }

      .logo-title-wrapper {
        position: relative;
        .title {
          font-weight: 500;
          font-size: 32px;
          color: #1d2129;
          line-height: 40px;
        }
        .open,
        .close {
          position: absolute;
          top: -2px;
          left: 180px;
          display: flex;
          justify-content: center;
          align-items: center;
          font-weight: 600;
          font-size: 12px;
          color: #ffffff;
          line-height: 12px;
          width: 50px;
          height: 19px;
          background: linear-gradient(222deg, #ff7a66 0%, #ff5b60 100%);
          border-radius: 60px;
        }
        .close {
          color: #919aa5;
          width: 64px;
          background: linear-gradient(222deg, #f2f3f5 0%, #dbdbdb 100%);
        }
      }
      .text {
        font-weight: 400;
        font-size: 14px;
        color: #919aa5;
        line-height: 22px;
        margin: 12px 0 24px 0;
      }
      .btn-wrapper {
        margin-bottom: 16px;
      }
      .bill-wrapper {
        font-weight: 500;
        font-size: 16px;
        color: #1890ff;
        line-height: 22px;
      }
      .msg-wrapper {
        margin-top: 24px;
        .collection {
          &.active {
            margin-left: 81px;
            position: relative;
            &::after {
              content: '';
              display: block;
              position: absolute;
              top: 6px;
              left: -40px;
              width: 1px;
              height: 38px;
              background: #e5e6eb;
              border-radius: 0px 0px 0px 0px;
            }
          }
          font-weight: 400;
          font-size: 16px;
          color: #4e5969;
          line-height: 22px;
          .num {
            margin-top: 4px;
            font-weight: 600;
            font-size: 18px;
            color: #1890ff;
            line-height: 22px;
          }
        }
      }
      .money-wrapper {
        .money {
          display: flex;
          align-items: center;
          margin-top: 24px;
          img {
            width: 54px;
            height: 54px;
          }
          .money-title {
            font-weight: 500;
            font-size: 16px;
            color: #1d2129;
            line-height: 22px;
            margin-bottom: 3px;
          }
          .money-text {
            font-weight: 400;
            font-size: 12px;
            color: #919aa5;
            line-height: 22px;
          }
        }
      }
    }
  }
</style>
